<?php

    $callNo = $_POST['callNo'];
    $libraryCardNo = $_GET['libraryCardNo'];
    $libraryNo = $_COOKIE['libraryNo'];
    require('db_connection.php');
    $query = "SELECT materialID FROM tblcollection WHERE accessionNo LIKE '$callNo' AND libraryNo LIKE '$libraryNo' ";
    //echo $query;
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result))
    {
      $materialID = $row['materialID'];
    }
    if($materialID =='')
    {
        //echo $materialID;
    }
    else
    {
       // echo 'meron';
    }
    
    $query2 = "SELECT userID FROM tblclient WHERE libraryCardNo='$libraryCardNo'";
    //echo $query2;
    $result2 = mysql_query($query2);
    while ($row = mysql_fetch_array($result2))
    {
      $userID = $row['userID'];
    }

    $query3 = "DELETE FROM tblcirculation WHERE materialID='$materialID' AND userID='$userID' AND status='borrowed'";
    $result = mysql_query($query3);
    //echo $query3;
        echo"<script> alert('Material Returned! Thank You!');</script>";
        echo"'<script>document.location.href='transactions.php?libraryCardNo=$libraryCardNo&libraryNo=$libraryNo'</script>'";


?>
